import router from '@ohos.router';
import prompt from '@ohos.prompt';
import ajax from '../../http/http';

export default {
    data: {
        checked: false,
        user: {
            username: '',
            password: '',
            nickname: '',
            email: '',
            phoneNumber: ''
        }
    },
    goBack() {
        router.back();
    },
    usernameChange(e) {
        this.user.username = e.value;
    },
    nicknameChange(e) {
        this.user.nickname = e.value;
    },
    emailChange(e) {
        this.user.email = e.value;
    },
    passwordChange(e) {
        this.user.password = e.value;
    },
    phoneChange(e) {
        this.user.phoneNumber = e.value;
    },
    checkedDeal() {
        this.checked = !this.checked;
    },
    register() {
        ajax.post('/account/register', this.user, (result) => {
            if (result.code == 20000) {
                prompt.showToast({
                    message: result.msg
                });
                // 成功后跳转首页
                router.push({
                    url: 'pages/index/index'
                });
            } else {
                prompt.showToast({
                    message: result.msg
                });
            }
        });
    }
}
